<!DOCTYPE html>
<html>
<head>
    <title> 登录 </title>
    <style>
        html, body {
            height: 100%;
        }

        header .header {
            background-color: #fff;
            height: 45px;
        }

        header a img {
            width: 134px;
            margin-top: 4px;
        }

        .login-page {
            width: 360px;
            padding: 8% 0 0;
            margin: auto;
        }

        .login-page .form .login {
            margin-top: -31px;
            margin-bottom: 26px;
        }

        .form {
            position: relative;
            z-index: 1;
            background: #FFFFFF;
            max-width: 360px;
            margin: 0 auto 100px;
            padding: 45px;
            text-align: center;
            box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
        }

        .form input {
            font-family: "Roboto", sans-serif;
            outline: 0;
            background: #f2f2f2;
            width: 100%;
            border: 0;
            margin: 0 0 15px;
            padding: 15px;
            box-sizing: border-box;
            font-size: 14px;
        }

        .form button {
            font-family: "Roboto", sans-serif;
            text-transform: uppercase;
            outline: 0;
            background-color: #328f8a;
            background-image: linear-gradient(45deg, #328f8a, #4ab977);
            width: 100%;
            border: 0;
            padding: 15px;
            color: #FFFFFF;
            font-size: 14px;
            -webkit-transition: all 0.3 ease;
            transition: all 0.3 ease;
            cursor: pointer;
        }

        .form .message {
            margin: 15px 0 0;
            color: #b3b3b3;
            font-size: 12px;
        }

        .form .message a {
            color: #4CAF50;
            text-decoration: none;
        }

        .container {
            position: relative;
            z-index: 1;
            max-width: 300px;
            margin: 0 auto;
        }

        body {
            background-color: #328f8a;
            background-image: linear-gradient(160deg, #328f8a, #4ab977);
            font-family: "Roboto", sans-serif;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }

        .password-tip {
            font-size: 9px;
            color: #6e6464;
        }
    </style>
</head>
<body>
<div class="login-page">
    <div class="form">
        <div class="login">
            <div class="login-header">
                <h3>登录</h3>
                <p class="password-tip">密码位于${user.home}/desktop-tomcat/password</p>
            </div>
        </div>

        <input id="password" type="password" placeholder="password"/>
        <button onclick="doLogin()">登录</button>
        <p id="message" class="message"></p>


    </div>
</div>
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/jsencrypt/3.2.1/jsencrypt.min.js"></script>
<script type="text/javascript">

    function doLogin() {
        let password = document.getElementById("password").value
        document.getElementById("message").innerText = ""
        let encrypt = new JSEncrypt();
        let PUBLIC_KEY = "${rsapublic}";
        encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');
        let encrypted = encrypt.encrypt(password);

        async function postData(url = '', data) {
            // Default options are marked with *
            const response = await fetch(url, {
                method: 'POST',
                cache: 'no-cache',
                credentials: 'same-origin',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: data
            });
            return response.json();
        }

        postData('/tomcat/api/login', "password=" + encrypted)
            .then(data => {
                if (data.status) {
                    window.location.href = "/"
                    return
                }
                document.getElementById("message").innerText = "密码错误"
            });
    }
</script>
</body>
</html>
